

* Effect of increasing the distance to closest 
* betting house on educatonal performance

*** Treatment: logged distance to closest betting house
*cd "~/Dropbox/EUI/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Data"
cd "/Users/mariadelmarcanizaresespadafor/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Data"

use "gambling_data.dta", clear


xtset school_id year


** Publico=1 -> charter schools
** Publico=2 -> public schools

** Renta2=0 -> poorer 
** Renta2=1 -> richer
*cd "~/Dropbox/EUI/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Estimates"
cd "/Users/mariadelmarcanizaresespadafor/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Estimates"


*** General
xtreg pau logdist_year i.year, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) replace addlabel (Income, All, School, All, Level, 90)
xtreg pau logdist_year i.year, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, All, School, All, Level, 95)

*** Charter
xtreg pau logdist_year i.year if publico==1 , fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) append addlabel (Income, All, School, Charter, Level, 90)
xtreg pau logdist_year i.year if publico==1, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, All, School, Charter, Level, 95)

***Public
xtreg pau logdist_year i.year if publico==2 , fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) append addlabel (Income, All, School, Public, Level, 90)
xtreg pau logdist_year i.year if publico==2, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, All, School, Public, Level, 95)

*** Charter, poor
xtreg pau logdist_year i.year if publico==1 & renta2==0, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) append addlabel (Income, Poor, School, Charter, Level, 90)
xtreg pau logdist_year i.year if publico==1 & renta2==0, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, Poor, School, Charter, Level, 95)

*** Charter, rich
xtreg pau logdist_year i.year if publico==1 & renta2==1, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) append addlabel (Income, Rich, School, Charter, Level, 90)
xtreg pau logdist_year i.year if publico==1 & renta2==1, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, Rich, School, Charter, Level, 95)

*** Public, poor
xtreg pau logdist_year i.year if publico==2 & renta2==0, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) append addlabel (Income, Poor, School, Public, Level, 90)
xtreg pau logdist_year i.year if publico==2 & renta2==0, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, Poor, School, Public, Level, 95)

*** Public, rich
xtreg pau logdist_year i.year if publico==2 & renta2==1, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(90) append addlabel (Income, Rich, School, Public, Level, 90)
xtreg pau logdist_year i.year if publico==2 & renta2==1, fe
regsave logdist_year using "distance1.dta", tstat pval ci level(95) append addlabel (Income, Rich, School, Public, Level, 95)

use "distance1.dta", clear

gen ci_lower90 = ci_lower if Level==90
gen ci_upper90 = ci_upper if Level==90
gen ci_lower95 = ci_lower if Level==95
gen ci_upper95 = ci_upper if Level==95

gen inc = 0 if Income=="Poor"
replace inc = 1 if Income=="All" 
replace inc = 2 if Income=="Rich" 

gen charter = 0 if School=="Charter"
replace charter = 1 if School=="Public"
replace charter = 2 if School=="All"

save "distance2.dta", replace 
